package actions;

import game.constants.ReferenceAction;
import game.constants.ReferenceObject;
import game.constants.ReferenceSpecialFeature;
import interfaces.ActionInterface;
import interfaces.impl.Action;
import objects.SpetialFeature;
import universe.Universe;


public class ActionGatherMineral extends Action{

	@Override
	public ActionInterface cloneAction() {
		ActionGatherMineral action = new ActionGatherMineral();
		action.modifyAction(this);
		return action;
	}

	@Override
	public boolean processActionChild(Universe universe) {
		
		if (target.getObjectReference()!=ReferenceObject.OBJECT_REFERENCE_MINERALS){
			return false;
		}
		
		SpetialFeature mineralsToGather = target.getFeature(ReferenceSpecialFeature.SPETIAL_FEATURE_CURRENT_LIFE);
		if(mineralsToGather==null){
			return false;
		}
		
		SpetialFeature mineralQuantity = source.getFeature(ReferenceSpecialFeature.SPETIAL_FEATURE_MINERAL_QUANTITY_TO_GATHER);
		
		if (mineralQuantity == null ){
			return false;
		}
		
		
		mineralsToGather.setValue(mineralsToGather.getValue()-mineralQuantity.getValue());
		
		ActionReciveMinerals actionReciveMinerals = new ActionReciveMinerals();
		actionReciveMinerals.setSource(target);
		actionReciveMinerals.setTarget(source);
		actionReciveMinerals.setQuantity(mineralQuantity.getValue());
		universe.setAction(actionReciveMinerals);
		
		/*SpetialFeature mineralToCarry = source.getFeature(ReferenceSpecialFeature.SPETIAL_FEATURE_MINERAL_QUANTITY);
		
		if(mineralToCarry==null){
			return false;
		}
		
		mineralToCarry.setValue(mineralToCarry.getValue()+mineralQuantity.getValue());*/
		
		
		return true;
	}

	@Override
	public void initializeName() {
		name="Gather Minerals";
		
	}

	@Override
	public void initializeId() {
		this.id=ReferenceAction.ACTION_GATHER_MINERALS;
		
	}

	@Override
	public void modifyChild(ActionInterface action) {
		
		
	}
	
	

}
